<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    $(function() {
        $('#productionEditForm').form({
            url : '${path}/production/edit',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    var form = $('#productionEditForm');
                    parent.$.messager.alert('错误', eval(result.msg), 'error');
                }
            }
        });
    });
  //检查图片的格式是否正确,同时实现预览  
    function setImagePreview(obj, localImagId, imgObjPreview,maxwidth,maxheight) {  
        var array = new Array('gif', 'jpeg', 'png', 'jpg', 'bmp'); //可以上传的文件类型  
        if (obj.value == '') {  
            $.messager.alert("让选择要上传的图片!");  
            return false;  
        }  
        else {  
            var fileContentType = obj.value.match(/^(.*)(\.)(.{1,8})$/)[3]; //这个文件类型正则很有用   
            ////布尔型变量  
            var isExists = false;  
            //循环判断图片的格式是否正确  
            for (var i in array) {  
                if (fileContentType.toLowerCase() == array[i].toLowerCase()) {  
                    //图片格式正确之后，根据浏览器的不同设置图片的大小  
                    if (obj.files && obj.files[0]) {  
                        //火狐下，直接设img属性   
                        imgObjPreview.style.display = 'block';  
                        imgObjPreview.style.width = maxwidth;  
                        imgObjPreview.style.height = maxheight;  
                        //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式   
                        imgObjPreview.src = window.URL.createObjectURL(obj.files[0]);  
                    }  
                    else {  
                        //IE下，使用滤镜   
                        obj.select();  
                        var imgSrc = document.selection.createRange().text;  
                        //必须设置初始大小   
                        localImagId.style.width = maxheight;  
                        localImagId.style.height = maxheight;  
                        //图片异常的捕捉，防止用户修改后缀来伪造图片   
                        try {  
                            localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";  
                            localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;  
                        }  
                        catch (e) {  
                            $.messager.alert("您上传的图片格式不正确，请重新选择!");  
                            return false;  
                        }  
                        imgObjPreview.style.display = 'none';  
                        document.selection.empty();  
                    }  
                    isExists = true;  
                    return true;  
                }  
            }  
            if (isExists == false) {  
                $.messager.alert("上传图片类型不正确!");  
                return false;  
            }  
            return false;  
        }  
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow: auto;padding: 3px;">
        <form id="productionEditForm" method="post" enctype="multipart/form-data" >
            <table class="grid">
                <tr>
                   <td style="width:100px">品牌名称</td>
                    <td style="width:240px">
                    	<input name="id" type="hidden"  value="${production.id}">
                   		<input name="manName" type="text" placeholder="请输入名称" class="easyui-validatebox" data-options="required:true" value="${production.manName}">
                   	</td>
                    <td style="width:100px">库存数量</td>
                    <td>
                    	<input name="manNum" type="text" placeholder="请输入数量" class="easyui-validatebox" data-options="required:true" value="${production.manNum}">
                    </td>
                </tr>
                <tr>
                  	<td>售价</td>
                    <td>
                    	<input name="manPrice" type="text" placeholder="请输入价格" class="easyui-validatebox" data-options="required:true" value="${production.manPrice}">
                    </td>
                    <td>品牌</td>
                    <td>
                    	<select id="carftsmanId" name="carftsmanId" data-options="required:true" class="easyui-validatebox">
                    		<option value="">---</option>
                    		<c:forEach items="${brandList }" var="brandVO" >
                    			<option value="${brandVO.id}" <c:if test="${brandVO.id eq production.carftsmanId}">selected="selected"</c:if>
                    			<c:if test="${brandVO.manKey eq production.manKey}">selected="selected"</c:if>>${brandVO.manBrand }</option>
                    		</c:forEach>
                    	</select>
                    </td>
                </tr>
                 <tr>
                  	<td>产品唯一标识</td>
                    <td>
                    	<input name="manProductKey" type="text" placeholder="产品唯一标识" class="easyui-validatebox" data-options="required:true" value="${production.manProductKey}">
                    </td>
                </tr>
                 <tr>
                	<td>标签</td>
                	<td colspan="3">
                		<c:forEach items="${tagList }" var="tagVO">
                			<div style="width:100px; float: left;"><input type="checkbox" name="protags" value="${tagVO.tagid}" <c:if test="${tagVO.isSel gt 0}">checked="checked"</c:if>/>${tagVO.tagName}</div>
                		</c:forEach>
                	</td>
                </tr>
                <tr>
                    <td>获奖情况</td>
                    <td colspan="3">
                    	<textarea cols="60" rows="3" name="manWin" placeholder="获奖情况">${production.manWin}</textarea>
                    </td>
                </tr>
                <tr>
                    <td>产品描述</td>
                    <td colspan="3">
                    	<textarea cols="60" rows="3" name="manDescribe" placeholder="产品描述">${production.manDescribe}</textarea>
                    </td>
                </tr>
                <tr>
                    <td>产品链接</td>
                    <td colspan="3">
                    	<input style="width:525px" name="manProductlink" type="text" class="easyui-validatebox"  value="${production.manProductlink}">
                    </td>
                </tr>
                
                <tr>
                    <td>封面图</td>
                    <td colspan="3">
                    	<div id="coverImg">  
						    <c:if test="${not empty production.manCover}">
								<img id="previewcover"  src="${production.manCover}" style="width: 150px; height: 170px;"/>   
							</c:if>
							<c:if test="${empty production.manCover}">
								<img id="previewcover"  src="/static/style/images/hui.jpg" style="width: 150px; height: 170px;"/>   
							</c:if>  
						</div>  
                    	    选择图片:<input id="idFile1" name="pic_manCove" onchange="javascript:setImagePreview(this,coverImg,previewcover,'150px','170px');" type="file" />
                    	<input id="manCover" name="manCover"  type="hidden" value="${production.manCover}"/>  
                    </td>
                </tr>
                <tr>
                    <td>产品图片</td>
                    <td colspan="3">
                    	<c:forEach items="${proimgList}" var="proimgVO" varStatus="vs">
                    		<div id="localImag${vs.index+1 }">  
                    			<c:if test="${empty proimgVO.manImg }">
		                    		<img id="preview${vs.index+1 }"  src="/static/style/images/hui.jpg" style="width: 150px; height: 170px;"/>
		                    	</c:if>
		                    	<c:if test="${not empty proimgVO.manImg }">
		                    		<img id="preview${vs.index+1 }"  src="${proimgVO.manImg}" style="width: 150px; height: 170px;"/>
		                    	</c:if>
		                    	<input name="upproimg" onchange="javascript:setImagePreview(this,localImag${vs.index+1 },preview${vs.index+1 },'150px','170px');" type="file" />
		                    	<input name="imagIds"  type="hidden" value="${proimgVO.id}"/>  
	                    	</div>
                    	</c:forEach>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>